{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "matplotlib.use('TkAgg')\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "from matplotlib import cm\n",
    "from matplotlib.colors import LightSource\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "matplotlib.rcParams['font.sans-serif'] = ['SimHei']\n",
    "import datawash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 遍历所有用户，读取需要的信息\n",
    "list1 = list()\n",
    "list2 = list()\n",
    "list3 = list()\n",
    "\n",
    "jsons = datawash.datajsons()\n",
    "for user in jsons:\n",
    "    try:\n",
    "        list1.append([user['voteupCount'],user['thankedCount']])\n",
    "        list2.append([user['followingCount'],user['followerCount']])\n",
    "        list3.append([user['favoriteCount'],user['favoritedCount']])\n",
    "    except:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 绘图用到的颜色\n",
    "black = '#212121'\n",
    "gray = '#727272'\n",
    "red = '#D32F2F'\n",
    "orange = '#FF9500'\n",
    "orange2 = '#FFF1DE'\n",
    "green = '#99FF33'\n",
    "brown = '#cc6600'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 100000以下赞同数和感谢数空间分布\n",
    "fig = plt.figure()  \n",
    "ax = Axes3D(fig)\n",
    "\n",
    "# 生成网格上所有点的坐标\n",
    "start = 0 # 起始点\n",
    "stop = 100000 # 终止点\n",
    "step = int(stop/70) # 步长\n",
    "X = np.arange(start, stop, step)\n",
    "Y = np.arange(start, stop, step)  \n",
    "X, Y = np.meshgrid(X, Y)\n",
    "\n",
    "Z = np.zeros_like(X)\n",
    "for i in list1:\n",
    "    if i[0] >= start and i[0] < stop and i[1] >= start and i[1] < stop:\n",
    "        Z[int((i[1]-start)/step),int((i[0]-start)/step)] += 1\n",
    "# 取对数，使图案更平缓  \n",
    "Z = np.log10(Z+1)\n",
    "# 绘图\n",
    "ls = matplotlib.colors.LightSource(270, -60)\n",
    "rgb = ls.shade(Z, cmap=plt.cm.gist_earth_r,vert_exag=0.1, blend_mode='soft')\n",
    "ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=rgb,linewidth=0, antialiased=True, shade=True)\n",
    "\n",
    "# 设置Z轴刻度\n",
    "zticks = np.arange(0, Z.max(), int(Z.max()/5))  \n",
    "zlabels = [int(10**x) for x in zticks]\n",
    "ax.set_zticks(zticks)\n",
    "ax.set_zticklabels(zlabels)\n",
    "\n",
    "# 设置标题，标签\n",
    "ax.set_title('100000以下赞同数和感谢数空间分布', color=orange, fontsize=20)\n",
    "ax.set_xlabel('赞同数', fontsize=14)\n",
    "ax.set_ylabel('感谢数', fontsize=14)\n",
    "ax.set_zlabel('用户数量（人）', fontsize=14)\n",
    "ax.set_facecolor(orange2)\n",
    "ax.invert_yaxis()\n",
    "\n",
    "fig.set_size_inches(12,8)\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 10000以下关注数和关注者数空间分布\n",
    "fig = plt.figure()  \n",
    "ax = Axes3D(fig)\n",
    "\n",
    "# 生成网格上所有点的坐标\n",
    "start = 0 # 起始点\n",
    "stop = 10000 # 终止点\n",
    "step = int(stop/70) # 步长\n",
    "X = np.arange(start, stop, step)\n",
    "Y = np.arange(start, stop, step)  \n",
    "X, Y = np.meshgrid(X, Y)\n",
    "\n",
    "Z = np.zeros_like(X)\n",
    "for i in list2:\n",
    "    if i[0] >= start and i[0] < stop and i[1] >= start and i[1] < stop:\n",
    "        Z[int((i[1]-start)/step),int((i[0]-start)/step)] += 1\n",
    "# 取对数，使图案更平缓  \n",
    "Z = np.log10(Z+1)\n",
    "# 绘图\n",
    "ls = matplotlib.colors.LightSource(270, -60)\n",
    "rgb = ls.shade(Z, cmap=plt.cm.gist_earth_r,vert_exag=0.1, blend_mode='soft')\n",
    "ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=rgb,linewidth=0, antialiased=True, shade=True)\n",
    "\n",
    "# 设置Z轴刻度\n",
    "zticks = np.arange(0, Z.max(), int(Z.max()/5))  \n",
    "zlabels = [int(10**x) for x in zticks]\n",
    "ax.set_zticks(zticks)\n",
    "ax.set_zticklabels(zlabels)\n",
    "\n",
    "# 设置标题，标签\n",
    "ax.set_title('10000以下关注数和关注者数空间分布', color=orange, fontsize=20)\n",
    "ax.set_xlabel('关注数', fontsize=14)\n",
    "ax.set_ylabel('关注者数', fontsize=14)\n",
    "ax.set_zlabel('用户数量（人）', fontsize=14)\n",
    "ax.set_facecolor(orange2)\n",
    "ax.invert_yaxis()\n",
    "\n",
    "fig.set_size_inches(12,8)\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 10000以下收藏答案数和答案被收藏数空间分布\n",
    "fig = plt.figure()  \n",
    "ax = Axes3D(fig)\n",
    "\n",
    "# 生成网格上所有点的坐标\n",
    "start = 0 # 起始点\n",
    "stop = 10000 # 终止点\n",
    "step = int(stop/70) # 步长\n",
    "X = np.arange(start, stop, step)\n",
    "Y = np.arange(start, stop, step)  \n",
    "X, Y = np.meshgrid(X, Y)\n",
    "\n",
    "Z = np.zeros_like(X)\n",
    "for i in list3:\n",
    "    if i[0] >= start and i[0] < stop and i[1] >= start and i[1] < stop:\n",
    "        Z[int((i[1]-start)/step),int((i[0]-start)/step)] += 1\n",
    "# 取对数，使图案更平缓  \n",
    "Z = np.log10(Z+1)\n",
    "# 绘图\n",
    "ls = matplotlib.colors.LightSource(270, -60)\n",
    "rgb = ls.shade(Z, cmap=plt.cm.gist_earth_r,vert_exag=0.1, blend_mode='soft')\n",
    "\n",
    "ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=rgb,linewidth=0, antialiased=True, shade=True)\n",
    "\n",
    "# 设置Z轴刻度\n",
    "zticks = np.arange(0, Z.max(), int(Z.max()/5))  \n",
    "zlabels = [int(10**x) for x in zticks]\n",
    "ax.set_zticks(zticks)\n",
    "ax.set_zticklabels(zlabels)\n",
    "\n",
    "# 设置标题，标签\n",
    "ax.set_title('10000以下收藏答案数和答案被收藏数空间分布', color=orange, fontsize=20)\n",
    "ax.set_xlabel('收藏答案数', fontsize=14)\n",
    "ax.set_ylabel('答案被收藏数', fontsize=14)\n",
    "ax.set_zlabel('用户数量（人）', fontsize=14)\n",
    "ax.set_facecolor(orange2)\n",
    "ax.invert_yaxis()\n",
    "\n",
    "fig.set_size_inches(12,8)\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
